import React, { Component, Fragment } from 'react';
import { Card, Descriptions, Image, Button, Space, Popconfirm } from 'antd'
import { connect } from 'dva';
import constant from '../../constant/constant'

class VerificationPage extends Component {
    constructor(props) {
        super(props)
    }

    componentDidMount() {
        this.props.dispatch({
            type: "application/getVerificationMechanismInformation",
            data: { verificationApplicationId: this.props.verification.technologyId }
        })
    }

    restartProcess = () => {
        this.props.dispatch({
            type:"application/restartProcess",
            data:{verificationApplicationId:this.props.verification.technologyId}
        })
    }

    renderNextButton = verification => {
        if(verification.verificationReport && verification.verificationStatement){
            return(
                <Space style={{marginTop:30}}>
                    <Popconfirm
                        title="确定要重新验证吗？重新验证后已有的验证文件会全部删除，并从资格审查阶段重新开始。"
                        onConfirm={this.restartProcess}
                    >
                        <Button type='primary'>重新验证</Button>
                    </Popconfirm>
                    <Button type='primary' onClick={this.goToNextProcess}>完成验证</Button>
                </Space>
            )
        }
    }

    goToNextProcess = () => {
        this.props.dispatch({
            type:"application/goToNextProcess",
            data:{
                verificationApplicationId:this.props.verification.technologyId
            }
        })
    }

    render() {
        return (
            <Fragment>
                <Descriptions title={(this.props.verificationInformation.verificationReport && this.props.verificationInformation.verificationStatement) ? <p>已完成验证</p> : <p>正在进行验证</p>} column={2} bordered={true}>
                    <Descriptions.Item label="验证机构">{this.props.verificationInformation.mechanismName}</Descriptions.Item>
                    <Descriptions.Item label="验证进行天数">{this.props.verificationInformation.ondays}</Descriptions.Item>
                    <Descriptions.Item label="验证报告">{this.props.verificationInformation.verificationReport ? <a href={constant.serverUrl + constant.fileUrl.mechanismUrl + this.props.verificationInformation.verificationReport}>{this.props.verificationInformation.verificationReport}</a> : "验证机构暂未上传"}</Descriptions.Item>
                    <Descriptions.Item label="验证声明">{this.props.verificationInformation.verificationStatement ? <a href={constant.serverUrl + constant.fileUrl.mechanismUrl + this.props.verificationInformation.verificationStatement}> {this.props.verificationInformation.verificationStatement}</a> : "验证机构暂未上传"}</Descriptions.Item>
                </Descriptions>
                {this.renderNextButton(this.props.verificationInformation)}
            </Fragment>
        )
    }
}

const mapStateToProps = state => {
    let verificationInformation = state.application.verificationInformation
    let verification = state.application.verification
    return {
        verificationInformation,
        verification
    }
}

export default connect(mapStateToProps)(VerificationPage)